import 'dart:io';

import 'package:flutter/material.dart';

void main() {
  runApp(new FromPlugin());
}

/*
 * 表单组件 <br/>
 * 需要传入的键：<br/>
 * 传入的值类型： <br/>
 * 传入的值含义：<br/>
 * 是否必传 ：
 */
class FromPlugin extends StatefulWidget {
  State<StatefulWidget> createState() {
    return new FromPluginState();
  }
}

/*
 * 页面功能 <br/>
 */
class FromPluginState extends State<StatefulWidget> {
  final key_btn_right = GlobalKey();
  TextEditingController _unameController = new TextEditingController();
  TextEditingController _pwdController = new TextEditingController();

  void initState() {
    super.initState();
  }

  Widget build(BuildContext context) {
    AppBar appBar = AppBar(
      leading: new IconButton(
        icon: new Icon(Icons.arrow_back),
        onPressed: () {},
      ),
      title: new Text('FlutterDesign'),
      centerTitle: true,
      actions: <Widget>[
        new Container(width: 0, height: 0),
        new Container(width: 0, height: 0),
      ],
      backgroundColor: Colors.blue,
    );

    return MaterialApp(
      home: new Scaffold(
        appBar: appBar,
        body: new Builder(builder: (BuildContext context) {
          return Form(
            key: key_btn_right,
            child: Column(
              children: <Widget>[
                TextFormField(
                  autofocus: true,
                  controller: _unameController,
                  decoration: InputDecoration(
                      labelText: '用户名',
                      hintText: '用户名或邮箱',
                      icon: Icon(Icons.person)),
                  //校验用户名
                  validator: (v) {
                    return v.trim().length > 0 ? null : '用户名不能为空';
                  },
                ),
                TextFormField(
                  controller: _pwdController,
                  decoration: InputDecoration(
                      labelText: '密码',
                      hintText: '您的登录密码',
                      icon: Icon(Icons.lock)),
                  obscureText: true,
                  //校验密码
                  validator: (v) {
                    return v.trim().length > 5 ? null : '密码不能少于6位';
                  },
                ),
                RaisedButton(
                  child: Text('登录'),
                  onPressed: () {
                    if ((key_btn_right.currentState as FormState).validate()) {
                      //验证通过提交数据
                      print('验证通过提交数据');
                    }
                  },
                ),
              ],
            ),
          );
        }),
        backgroundColor: Colors.white,
        bottomNavigationBar: null,
      ),
    );
  }
}
